1 #include<windows.h>
2 #include<stdio.h>
3 #include<conio.h>
4 #include <stdlib.h>
5 #include<
string.h> //contains strcmp(),strcpy(),strlen(),etc
6 #include<ctype.h>
//contains toupper(), tolower(),etc
7 #include<dos.h>
//contains _dos_getdate
8 #include<time.h>

9
10 void
password();
11 void
mainmenu(void);
12 void
addmember(void);
13 void
deletemember(void);
14 void
searchmember(void);
15 void
viewmember(void);
16 void
editmember(void);
17 void
closeapp(void);
18 void
returnfunc(void);
19 void
event(void);
20 int
t(void);
21
22
23
24 void
addevent(void);
25 void
vieweevent(void);
26 void
deleteevent(void);
27
28 ///
list of global files
29 FILE *fp,*ft,*fs;
30 COORD coord = {
0, 0};
31
32 int
fm;
33
34 void
gotoxy (int x, int y)
35 {
36 coord.X = x; coord.Y = y;
// X and Y coordinates
37 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
38 }

39
40 struct
member{
41     
int ID;
42     
char name[20];
43     
char add[20];
44     
char dept[20];
45     
int Phone_no;
46
47     
int no;
48     
char title[20];
49     
char z[100];
50     
char date[20];
51
52 };

53
54 struct
member stu;
55
56
57
58
59 int
main(){
60 password();
61 getch();

62 return
0;
63 }

64
65 void
mainmenu(){
66     
int choice;
67     system(
"cls");
68     gotoxy(
20,3);
69     printf(
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd MAIN MENU \xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd");
70 gotoxy(
20,5);printf("1. Add Members\n");
71 gotoxy(
20,7);printf("2. Delete Members\n");
72 gotoxy(
20,9);printf("3. Search Members\n");
73 gotoxy(
20,11);printf("4. View Members\n");
74 gotoxy(
20,13);printf("5. Event\n");
75 gotoxy(
20,15);printf("6. Edit Members Information\n");
76 gotoxy(
20,17);printf("7. Close application\n");
77 gotoxy(
20,18);printf("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd");
78 gotoxy(
20,19);t();
79 gotoxy(
20,23);
80 printf(
"Enter Your Choice: ");
81 //scanf(
"%d",&choice);
82 switch
(getch()){
83 case
'1':
84 addmember();

85 break
;
86 case
'2':
87 deletemember();

88 break
;
89 case
'3':
90 searchmember();

91 break
;
92 case
'4':
93 viewmember();

94 break
;
95 case
'5':
96 event
();
97 break
;
98 case
'6':
99 editmember();

100 case
'7':{
101 system(
"cls");
102 gotoxy(
16,3);
103 printf(
"\t IT CLUB Management System\n");
104 gotoxy(
16,5);
105 printf(
"THANK YoU FoR USING OUR PROGRAM");
106 printf(
"\n\n*****************************************************************************");
107
108 exit(
0);
109 }

110 default
:{
111 gotoxy(
20,22);printf("Wrong!!Correct Option");
112 if
(getch())
113 mainmenu();
114
115 }
116 }

117
118 //
return 0;
119 }

120 void
addmember(void){
121 system(
"cls");
122
123       gotoxy(
26,2);
124      printf(
"\xcd\xcd\xcd\xcd Add MEMBER INFO \xcd\xcd\xcd");
125     
int print = 25;
126     FILE *fp;
127     fp = fopen(
"record_nxt.txt","ab+");
128 // SetColor(
45);
129     
if(fp == NULL){
130         MessageBox(
0,"Error in Opening file\nMake sure your file is not write protected","Warning",0);
131
132     }
133     
else
134
135     {

136         ///
fflush(stdin);
137         gotoxy(print,
6);printf("Member ID: ");scanf("%d",&stu.ID);
138         
//here you can confirms the ID
139         fflush(stdin);
140         gotoxy(print,
8);printf("Name: ");gets(stu.name);
141         gotoxy(print,
10);printf("Address: ");gets(stu.add);
142         gotoxy(print,
12);printf("dept. name: ");gets(stu.dept);
143         gotoxy(print,
14);printf("Phone Number: ");scanf("%d",&stu.Phone_no);
144         ///
gotoxy(print,20);printf("Phone Number: ");scanf("%d",&stu.phone_no);
145         fwrite(&stu,
sizeof(stu), 1, fp);
146
147     }
148
149     fclose(fp);
150     gotoxy(
40,17); printf("The record is sucessfully added");
151      gotoxy(
40,18);printf("Save any more Y/N");
152     
if(getch()=='n')
153     mainmenu();
154     
else
155     system(
"cls");
156     addmember();
157 }

158
159
160
161
162 void
deletemember( ){
163 system (
"cls");
164 gotoxy(
26,2);
165      printf(
"\xcd\xcd\xcd\xcd Delete MEMBER \xcd\xcd\xcd");
166
167
168 /*

169     ///
print_heading("Delete Record");
170     ///
SetColor(45);
171     
char m_id[15];
172     
int isFound = 0, print = 37;
173     gotoxy(
37,10);printf("Enter ID to Delete: ");fflush(stdin);
174     gets(m_id);
175     FILE *fp, *temp;
176     fp = fopen(
"record_nxt.txt","rb");
177     temp = fopen(
"temp.txt", "wb");
178     
while(fread(&stu, sizeof(stu),1,fp) == 1)
179     printf(
"record found");{
180         
if(strcmp(m_id, stu.ID) == 0){
181             ///
printf("record found");
182             fwrite(&stu,
sizeof(stu),1,temp);
183         }
184
185     }
186     fclose(fp);
187     fclose(temp);
188     
remove("record_nxt.txt");
189     rename(
"temp.txt","record_nxt.txt");
190     gotoxy(
37,12);printf("The record is sucessfully deleted\n");
191     returnfunc();

192
193 ///
SetColor(28);
194     
return;*/
195
196
197
198
199
200
201 int
d;
202 char
another='y';
203 while
(another=='y') //infinite loop
204 {
205     system(
"cls");
206     gotoxy(
26,2);
207      printf(
"\xcd\xcd\xcd\xcd Delete MEMBER \xcd\xcd\xcd");
208 gotoxy(
10,5);
209 printf(
"Enter the Member ID to delete:");
210 scanf(
"%d",&d);
211 fp=fopen(
"record_nxt.txt","rb+");
212 rewind(fp);
///reposition file pointer to sream's beggining
213 while
(fread(&stu,sizeof(stu),1,fp)==1)
214 {

215 if
(stu.ID==d)
216 {
217
218
219 gotoxy(
10,8);
220 printf(
"Member name is %s",stu.name);
221 gotoxy(
10,9);
222 //printf(
"phone No. is %d",stu.phone);
223 fm=
'Z';
224 }
225 }

226 if
(fm!='Z')
227 {
228 gotoxy(
10,10);
229 printf(
"No record is found in LIST");
230 if
(getch())
231 mainmenu();
232 }

233 if
(fm=='Z' )
234 {
235 gotoxy(
10,7);
236 printf(
"The Member is available");
237 gotoxy(
10,10);
238 printf(
"Do you want to delete it?(Y/N):");
239 if
(getch()=='y')
240 {
241 ft=fopen(
"test.txt","wb+"); //temporary file for delete
242 rewind(fp);

243 while
(fread(&stu,sizeof(stu),1,fp)==1)
244 {

245 if
(stu.ID!=d)
246 {

247 ///
fseek(ft,0,SEEK_CUR);
248 fwrite(&stu,
sizeof(stu),1,ft); //write all in tempory file except that
249 }
//we want to delete
250 }
251 fclose(ft);
252 fclose(fp);

253 remove
("record_nxt.txt");
254 rename(
"test.txt","record_nxt.txt"); //copy all item from temporary file to fp except that
255 fp=fopen(
"record_nxt.txt","rb+"); //we want to delete
256 if
(fm=='Z')
257 {
258 gotoxy(
10,10);
259 printf(
"The record is sucessfully deleted");
260 gotoxy(
10,11);
261 printf(
"Delete another record?(Y/N)");
262 }
263 }

264 else

265 mainmenu();
266 fflush(stdin);
267 another=getch();
268 }
269 }
270 gotoxy(
10,15);
271 mainmenu();

272 ///
returnfunc();
273
274 }

275
276
277 void
searchmember(void){
278 system(
"cls");
279 int
s;
280 gotoxy(
10,3);
281 printf(
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd SEARCH MEMBER \xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd");
282 gotoxy(
10,5);
283 printf(
"Enter the Member ID to search:");
284 scanf(
"%d",&s);
285 fp=fopen(
"record_nxt.txt","rb+");
286 rewind(fp);
///reposition file pointer to sream's beggining
287 while
(fread(&stu,sizeof(stu),1,fp)==1)
288 {

289 if
(stu.ID==s)
290 {
291
292 gotoxy(
10,7);
293 printf(
"The Member is available");
294
295 gotoxy(
10,9);
296 printf(
"ID: %d",stu.ID);
297 gotoxy(
10,10);
298 printf(
"Name: %s",stu.name);
299 gotoxy(
10,11);
300 printf(
"ADress: %s",stu.add);
301 gotoxy(
10,12);
302 printf(
"Dept. : %s",stu.dept);
303 gotoxy(
10,13);
304 printf(
"Phone nO: %d",stu.Phone_no);
305
306 fm=
'Z';
307 }
308 }

309 if
(fm!='Z')
310 {
311 gotoxy(
10,10);
312 printf(
"No record is found in LIST");
313 if
(getch())
314
315 mainmenu();
316 }
317
318 {
319 gotoxy(
10,9);
320 printf(
"");
321 fclose(fp);
322 returnfunc();
323 getch();
324 }}

325
326 void
viewmember(void){
327
328 system(
"cls");
329
330 FILE *fp;

331 int
i=0,j;
332 system(
"cls");
333 gotoxy(
15,1);
334 printf(
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd Members List \xcd\xcd\xcd\xcd\xcd\xcd");
335 gotoxy(
2,3);
336 printf(
" MEM_ID MEMBER NAME ADDRESS DEPT PHONE_NO ");
337 j=
5;
338 fp=fopen(
"record_nxt.txt","rb");
339 while
(fread(&stu,sizeof(stu),1,fp)==1)
340 {
341 gotoxy(
3,j);
342 printf(
"%d",stu.ID);
343 gotoxy(
14,j);
344 printf(
"%s",stu.name);
345 gotoxy(
28,j);
346 printf(
"%s",stu.add);
347 gotoxy(
40,j);
348 printf(
"%s",stu.dept);
349 gotoxy(
50,j);
350 printf(
"%d",stu.Phone_no);
351 ///
gotoxy(57,j);
352 ///
printf("%d",stu.phone_no);
353 gotoxy(
69,j);
354 ///
printf("%d",a.rackno);
355 printf(
"\n\n");
356 j++;
357 i=i+
1;
358 }
359 gotoxy(
3,25);
360 printf(
"Total Members =%d",i);
361 fclose(fp);
362 gotoxy(
35,25);
363 returnfunc();
364 getch();
365 }

366
367 void
event(void){
368
369 system(
"cls");
370 int
i;
371 gotoxy(
20,3);
372 printf(
"\xcd\xcd\xcd\xcd\xcd\xcd EVENT MENU \xcd\xcd\xcd\xcd\xcd\xcd");
373 // show_mouse();

374 gotoxy(
20,5);
375 printf(
"1. Add Event ");
376 gotoxy(
20,7);
377 printf(
"2. View Event");
378 gotoxy(
20,9);
379 printf(
"3. Delete Event");
380 gotoxy(
20,11);
381 printf(
"4. Mainmenu");
382 gotoxy(
20,12);printf("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd");
383 gotoxy(
20,15);printf("Enter Your Choice");
384 switch
(getch()){
385 case
'1':
386 addevent();

387 break
;
388 case
'2':
389 vieweevent();

390 break
;
391 case
'3':
392 deleteevent();

393 case
'4':
394 mainmenu();

395 default
:{
396 gotoxy(
20,22);printf("Wrong!!Correct Option\a");
397 if
(getch())
398 mainmenu();
399
400 }
401 }
402 }

403
404 void
addevent(){
405     system(
"cls");
406 gotoxy(
26,2);
407      printf(
"\xcd\xcd\xcd\xcd Add Event \xcd\xcd\xcd");
408     
int print = 25;
409     fp = fopen(
"record.dat","ab+");
410 // SetColor(
45);
411     
if(fp == NULL){
412         MessageBox(
0,"Error in Opening file\nMake sure your file is not write protected","Warning",0);
413
414     }
else{
415         ///
fflush(stdin);
416         ///
gotoxy(print,10);printf("event no: ");scanf("%d",&stu.no);
417         
//here you can confirms the ID
418         fflush(stdin);
419         gotoxy(print,
5);printf("event date:");gets(stu.date);
420         gotoxy(print,
6);printf("Event name: ");gets(stu.title);
421         gotoxy(print,
7);printf("Details: ");gets(stu.z);
422         fwrite(&stu,
sizeof(stu), 1, fp);
423         gotoxy(
40,12); printf("The record is sucessfully added");
424     }
425
426     fclose(fp);
427 gotoxy(
40,13);printf("Save any more Y/N");
428     
if (getch()=='n')
429     mainmenu();
430     
else
431     system(
"cls");
432     addevent();
433
434 gotoxy(
25,20);
435 returnfunc();
436 getch();
437 }

438
439 void
deleteevent()
440 {
441     system(
"cls");
442     
char date[20];
443    fflush(stdin);
444
445     printf(
"\n\n\t..::DELETE event\n\t==========================\n\t..::Enterthe date to delete:");
446
447     gets(date);
448     fp=fopen(
"record.dat","r");
449     ft=fopen(
"temp.dat","w");
450     
while(fread(&stu,sizeof(stu),1,fp)!=0)
451     
if (stricmp(date,stu.date)!=0)
452     fwrite(&stu,
sizeof(stu),1,ft);
453     fclose(fp);
454     fclose(ft);
455     
remove("record.dat");
456     rename(
"temp.dat","record.dat");
457     printf(
"\n\t\tRecord is delete");
458     ///
printf("Invalid choice");
459 gotoxy(
25,25);
460 returnfunc();
461 getch();
462 }

463
464
465
466 void
vieweevent()
467 {
468     system(
"cls");
469
470 int
j=5;
471 gotoxy(
1,1);
472 printf(
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd view events \xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd");
473 gotoxy(
1,3);printf("Event date event name Details");
474
475 fp=fopen(
"record.dat","rb");
476 while
(fread(&stu,sizeof(stu),1,fp)==1)
477 {
478
479 gotoxy(
1,j);
480 printf(
"%s",stu.date);
481 gotoxy(
18,j);
482 printf(
"%s",stu.title);
483 gotoxy(
46,j);
484 printf(
"%s",stu.z);
485 j++;
486 }
487 fclose(fp);
488
489 gotoxy(
25,25);
490 returnfunc();
491 getch();
492 }

493
494
495 void
editmember(void){
496 system(
"cls");
497
498 int
s,print=37;
499 gotoxy(
15,3);
500 printf(
"\xcd\xcd\xcd\xcd\xcd\xcd Edit MEMBER info \xcd\xcd\xcd\xcd\xcd\xcd");
501 gotoxy(
10,5);
502 printf(
"Enter the Member ID to edit:");
503 scanf(
"%d",&s);
504 fp=fopen(
"record_nxt.txt","rb+");
505 ///
rewind(fp); ///reposition file pointer to sream's beggining
506 while
(fread(&stu,sizeof(stu),1,fp)==1)
507 {

508 if
(stu.ID==s)
509 {
510
511 gotoxy(
10,7);
512 printf(
"The Member is available");
513 //gotoxy(print,
10);printf("ID: ");scanf("%d",&stu.ID);
514         
//here you can confirms the ID
515         fflush(stdin);
516         gotoxy(print,
12);printf("Name: ");gets(stu.name);
517         gotoxy(print,
14);printf("Address: ");gets(stu.add);
518         gotoxy(print,
16);printf("dept. name: ");gets(stu.dept);
519         gotoxy(print,
18);printf("Phone Number: ");scanf("%d",&stu.Phone_no);
520         gotoxy(print,
22);printf("The record is modified");
521         fseek(fp,-
sizeof(stu), SEEK_CUR);
522             fwrite(&stu,
sizeof(stu), 1, fp);
523
524 fm=
1;
525 break
;
526 }
527 }

528 if
(fm!=1)
529 {
530 gotoxy(
10,10);
531 printf(
"No record is found in LIST");
532 if
(getch())
533 mainmenu();
534 }
535
536 fclose(fp);
537
538 gotoxy(
37,22);
539 returnfunc();
540 getch();
541 }

542
543
544
545 void
returnfunc(void){{
546     gotoxy(
25,25);
547 printf(
"Press ENTER to return the main menu");
548 }

549 if
(getch()==13)
550 mainmenu();
551 }

552 int
t(void){
553 time_t t;
554 time(&t);
555 printf(
"Date and time:%s\n",ctime(&t));
556
557 return
0 ;
558 }

559
560 void
fordelay(int j)
561 {
int i,k;
562     
for(i=0;i<j;i++)
563          k=i;
564 }

565
566
567 void
password(void){
568 system(
"cls");
569 char
pass[10],ch,password[10]="z";
570 int
i=0;
571 gotoxy(
25,2);
572 printf(
"==== IT CLUB MANAGEMENT SYSTEM ====");
573 gotoxy(
20,5);
574 printf(
"Enter the password to Login:");
575 //scanf(
"%s",pass);
576 while
(ch!=13)
577 {
578 ch=getch();

579
580 if
(ch!=13 && ch!=8){
581 putch(
'*');
582 pass[i] = ch;
583 i++;
584 }
585 }
586 pass[i] =
'\0';
587
588
589 if
(strcmp(pass,password)==0){
590 gotoxy(
13,8);
591     printf(
"Password Matched!!");
592     gotoxy(
14,9);
593     printf(
"Loading ");
594 for
(i=0;i<=6;i++)
595         {
596             fordelay(
100000000);
597
598             printf(
".");
599         }
600                 system(
"cls");
601             mainmenu();
602         }
603         
else
604         gotoxy(
15,13);
605         printf(
"Password is invalid!!\a");
606         printf(
"\tENTER correct password");
607         getch();
608         main();
609 }


Gõ tìm kiếm nhanh...